import { TableColumnsType, Tooltip, Typography, Badge } from 'antd'
import { NavigateFunction } from 'react-router-dom'
import type { ITableData } from './types'
import { BadgeColorMap } from '@/constant'
import { CONTRACT_STATUS_TEXT, ORDER_STATUS_TEXT } from '@/constant/purchase'
export const useIndexColumns = ({
  params,
  onShowStyleModal,
  navigate,
  isRoot,
  onViewLogs,
}: {
  params: Record<string, any>
  onShowStyleModal: (info: ITableData) => void
  onViewLogs: (info: ITableData) => void
  navigate: NavigateFunction
  isRoot: boolean
}): TableColumnsType<ITableData> => [
  {
    title: '合同编号',
    dataIndex: 'contractCode',
    key: 'contractCode',
    align: 'center',
    width: 200,
    fixed: 'left',
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '合同状态',
    dataIndex: 'contractStatus',
    key: 'contractStatus',
    align: 'center',
    width: 170,
    render: (info) => {
      return <Badge color={BadgeColorMap[info]} text={CONTRACT_STATUS_TEXT[info] || '-'} />
    },
  },
  {
    title: '采购订单号',
    dataIndex: 'purchaseOrderCode',
    key: 'purchaseOrderCode',
    align: 'center',
    width: 200,
    render: (info, rows) => {
      return (
        <Typography.Link onClick={() => navigate('/purchase/order/detail?id=' + rows.purchaseId)}>
          {info}
        </Typography.Link>
      )
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    align: 'center',
    width: 180,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '供应商',
    dataIndex: 'supplierName',
    key: 'supplierName',
    align: 'center',
    width: 180,
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return info ? (
        <Tooltip placement="top" title={info}>
          {info}
        </Tooltip>
      ) : (
        '-'
      )
    },
  },
  {
    title: '订单状态',
    dataIndex: 'purchaseStatus',
    key: 'purchaseStatus',
    align: 'center',
    width: 150,
    render: (info) => {
      return info >= 0 ? <Badge color={BadgeColorMap[info]} text={ORDER_STATUS_TEXT[info] || '-'} /> : '-'
    },
  },
  {
    title: '首单/返单',
    dataIndex: 'orderType',
    key: 'orderType',
    align: 'center',
    width: 150,
    render: (info) => {
      return info === 0 ? '首单' : info === 1 ? '返单' : '-'
    },
  },
  {
    title: '大类',
    dataIndex: 'firstClassName',
    key: 'firstClassName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '年份',
    dataIndex: 'year',
    key: 'year',
    align: 'center',
    width: 150,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '仓库',
    dataIndex: 'warehouseName',
    key: 'warehouseName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '要求到货时间',
    dataIndex: 'requiredArrivalTime',
    key: 'requiredArrivalTime',
    align: 'center',
    width: 150,
    hidden: !isRoot,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '供应链交期',
    dataIndex: 'deliveryTime',
    key: 'deliveryTime',
    align: 'center',
    width: 150,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '采购总数',
    dataIndex: 'totalQty',
    key: 'totalQty',
    align: 'center',
    width: 150,
    render: (info) => {
      return info > 0 ? info : '-'
    },
  },
  {
    title: '采购总金额',
    dataIndex: 'totalAmount',
    key: 'totalAmount',
    align: 'center',
    width: 150,
    render: (info) => {
      return info > 0 ? info : '-'
    },
  },
  {
    title: '跟单确认时间',
    dataIndex: 'trackConfirmTime',
    key: 'trackConfirmTime',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '供管确认时间',
    dataIndex: 'supplyDuctConfirmTime',
    key: 'supplyDuctConfirmTime',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '财务确认时间',
    dataIndex: 'financialConfirmTime',
    key: 'financialConfirmTime',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '操作',
    dataIndex: 'op',
    key: 'op',
    align: 'center',
    fixed: 'right',
    width: 150,
    render: (_, rows) => {
      return <Typography.Link onClick={() => onViewLogs(rows)}>查看日志</Typography.Link>
    },
  },
]
